#pragma strict
//////////////////////////////////////////////////////
///查看 模型信息
//////////////////////////////////////////////////////
import System.Text;
class ModelInfo extends EditorWindow{
	var scrollPos:Vector2;

	@MenuItem("Level4/Fbx/ModelInfo")
	static function init(){
		var win:ModelInfo = EditorWindow.GetWindow.<ModelInfo>();
	}
	
	function OnGUI(){
		if( Selection.activeTransform){
			GUILayout.Label("Name:"+Selection.activeTransform.name);
			
			scrollPos = GUILayout.BeginScrollView(scrollPos);
				GUILayout.Box(GetChildrenInfo());
			GUILayout.EndScrollView();
		}
	}
	
	function OnInspectorUpdate(){
	    Repaint();
	}
	
	function GetChildrenInfo():String{
		var mfs:MeshFilter[] = Selection.activeTransform.GetComponentsInChildren.<MeshFilter>(true);
		var mesh:Mesh;
		var sb:StringBuilder = new StringBuilder();
		
		var vertCount:int = 0;
		var triCount:int = 0;
		for(var mf:MeshFilter in mfs){
			mesh = mf.sharedMesh;
			vertCount += mesh.vertices.length;
			triCount += mesh.triangles.length;
		}
		
		sb.Append("Vertex count:").Append(vertCount).Append("\n");
		sb.Append("TriangleCount:").Append(triCount/3);
		return sb.ToString();
	}
}